/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util.trayIcon;

import java.awt.AWTException;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import util.trayIcon.exception.BandejaNoSoportadaException;

/**
 *
 * @author Pato Pérez
 */
public class Bandeja {
    private SystemTray tray;

    public Bandeja() throws BandejaNoSoportadaException {
        if(SystemTray.isSupported()){
            tray = SystemTray.getSystemTray();
        }else throw new BandejaNoSoportadaException("Su sistema operativo no soporta un SystemTray");
    }
    
    public void agregarIconoBandeja(IconoBandeja iconoBandeja) throws AWTException{
        tray.add(iconoBandeja);
    }
    
    public void removeIconoBandeja(IconoBandeja iconoBandeja){
        tray.remove(iconoBandeja);
    }
    
    public List<IconoBandeja> getIconosBandeja(){
        List<IconoBandeja> iconos = new ArrayList<>();
        IconoBandeja[] trayIcons = (IconoBandeja[])tray.getTrayIcons();
        iconos.addAll(Arrays.asList(trayIcons));
        return iconos;
    }
    
    public static void main(String[] a){
        try {
            Bandeja b = new Bandeja();
            IconoBandeja ib = new IconoBandeja(Toolkit.getDefaultToolkit().getImage("twitter.png"), "Pulsame");
            IconoBandeja ib2 = new IconoBandeja(Toolkit.getDefaultToolkit().getImage("twitter.png"), "Pulsame 2");
            b.agregarIconoBandeja(ib);
            b.agregarIconoBandeja(ib2);
        } catch (AWTException | BandejaNoSoportadaException ex) {
            Logger.getLogger(Bandeja.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
